package com.xbongbong.saas.enums.product;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FlowStatusEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.List;
import java.util.Objects;

/**
 * 价目表适用范围
 * @author jiping.yang
 * @date 2022/7/13 16:45
 */
@Getter
public enum PriceSetScopeEnum {
    /**
     * 合同订单
     */
    CONTRACT(1, XbbRefTypeEnum.CONTRACT.getCode(), "enum.xbbRefType.name.contract"),
    /**
     * 报价单
     */
    QUOTATION(2, XbbRefTypeEnum.QUOTATION.getCode(), "enum.xbbRefType.name.quotation"),
    /**
     * 销售机会
     */
    SALES_OPPORTUNITY(3, XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.xbbRefType.name.sales_opportunity");

    private Integer type;

    private Integer businessType;

    private String name;


    PriceSetScopeEnum(Integer type, Integer businessType, String name) {
        this.type = type;
        this.businessType = businessType;
        this.name = name;
    }

    public static boolean getBusinessTypeByType(Integer businessType, List<Integer> typeList){
        boolean scope = false;
        for (PriceSetScopeEnum priceSetScopeEnum: values()){
            for (Integer item: typeList) {
                if (Objects.equals(priceSetScopeEnum.getType(), item) && Objects.equals(priceSetScopeEnum.getBusinessType(), businessType)) {
                    scope = true;
                    break;
                }
            }
        }
        return scope;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
